﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WmsApp.Service;
using WmsApp.WmsService;

namespace WmsApp.Window
{
    public partial class FormSelectCustomer : BaseForm
    {
        public FormSelectCustomer()
        {
            InitializeComponent();
            QueryData(" and 1=1 ");
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.Text = @"选择供应商（双击选中）";
        }

        private void QueryData(string sql)
        {
            var client = EntityServiceFactory.GetEntityService<Customer, CustomerService>();
            var list = client.GetEntityList(sql);
            this.gridControlMain.DataSource = list;
        }

        public Customer SelectCustomer { get; private set; }

        private void GridViewMainDoubleClick(object sender, EventArgs e)
        {
            var row = this.gridViewMain.GetRow(this.gridViewMain.FocusedRowHandle);
            if(row != null)
            {
                var customer = row as Customer;
                if(customer != null)
                {
                    SelectCustomer = customer;
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
            }
        }


    }
}
